<template>
	<view class="content">
		<view class="ffffff">
			<u-tabs :list="tabList" @click="change" lineWidth="40rpx" keyName="title" lineColor="rgba(255, 184, 0, 1)"
				:activeStyle="{
			  color: '#000000',
			  fontWeight: 800,
			  transform: 'scale(1.05)'}" :inactiveStyle="{
			  color: '#666666',
			     fontWeight: 800,
			    transform: 'scale(1)'
			}" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;"></u-tabs>
		</view>
		<view class="mainpadding">
			<view class="mainpadding ffffff border2 margin_bottom" v-for="item in list.data" :key="item.id"
				@click="jumpurl('/pages_goodsOrder/goodsOrderdetail')">
				<template v-if="active==0">
					<view class="flexbetween margin_bottom padding_bottom line_bottom">
						<!-- <view class="text_e color_zero">剩50分钟</view> -->
						<view class="text_ft flexright color_red">${{item.paymoney}}</view>
					</view>
					<view class="flex">
						<view class="textcenter margin_right2">
							<image class="imgBox" src="/static/images/index/take.png" mode=""></image>
							<view class="text_a color_zero">2.3</view>
							<view class="text_a color_nine">km</view>
						</view>
						<view>
							<view class="text_ft color_three">{{item.shop.name}}</view>
							<view class="text_d color_nine margin_top2">{{item.shop.addre}}{{item.shop.address}}</view>
						</view>
					</view>
					<image class="fromImg " src="/static/images/index/from.png" mode=""></image>
					<view class="flex">
						<view class="textcenter margin_right2">
							<image class="imgBox" src="/static/images/index/deliver.png" mode=""></image>
							<view class="text_a color_zero">2.3</view>
							<view class="text_a color_nine">km</view>
						</view>
						<view>
							<view class="text_ft color_three">{{item.username}}</view>
							<view class="text_d color_nine margin_top2">
								{{item.sheng}}{{item.shi}}{{item.qu}}{{item.useraddre}}</view>
						</view>
					</view>
					<!-- <view class="flexleft margin_top">
						<view class="specBox margin_right2">56kg</view>
						<view class="specBox">12*16*46＝126cm</view>
					</view> -->
					<!-- 備注 -->
					<view class="notes margin_top mainpadding text_c color_six" v-if="item.ordernotes">
						{{item.ordernotes}}</view>
					<view class="yellowBtn margin_top" @click.stop="qiangdan(item.id)">立即搶單</view>
				</template>
				<template v-else>
					<view class="flexbetween margin_bottom padding_bottom line_bottom">
						<!-- <view>
							<view class="text_e color_zero">剩50分钟</view>
							<view class="flexleft" v-if="item.type==1">
								<view class="buyBox margin_right2">幫買</view>
								
							</view>
							<view  v-if="item.type==0">
								<view class="takeBox">幫取</view>
							</view>
						</view> -->
						<view class="text_e color_theme" v-if="item.df_money">預估墊付${{item.df_money}}</view>
						<view class="text_ft flexright color_red">${{item.z_money}}</view>
					</view>
					<view class="flex">
						<view class="textcenter margin_right2">
							<image class="imgBox" src="/static/images/index/take.png" mode=""></image>
							<view class="text_a color_zero">2.3</view>
							<view class="text_a color_nine">km</view>
						</view>
						<view>
							<view class="text_ft color_three">{{item.to_name}}</view>
							<view class="text_d color_nine margin_top2">{{item.to_address}}</view>
						</view>
					</view>
					<image class="fromImg " src="/static/images/index/from.png" mode=""></image>
					<view class="flex">
						<view class="textcenter margin_right2">
							<image class="imgBox" src="/static/images/index/deliver.png" mode=""></image>
							<view class="text_a color_zero">2.3</view>
							<view class="text_a color_nine">km</view>
						</view>
						<view>
							<view class="text_ft color_three">{{item.go_name}}</view>
							<view class="text_d color_nine margin_top2">{{item.go_address}}</view>
						</view>
					</view>
					<view class="flexleft margin_top">
						<view class="specBox margin_right2" v-if="item.goods_kg">{{item.goods_kg}}kg</view>
						<view class="specBox" v-if="item.chang || item.kuan || item.gao">{{item.chang || 0}} *
							{{item.kuan || 0}} * {{item.gao || 0}}</view>
					</view>
					<!-- 備注 -->
					<view class="notes margin_top mainpadding text_c color_six" v-if="item.bei">{{item.bei}}</view>
					<view class="flexleft flex_wrap" v-if="item.images_arr.length">

						<view class="itemimgBox flexcenter margin_top2" v-for="(ite,index) in item.images_arr"
							:key="index">
							<!-- 已上傳 -->
							<view class="listleftimg1 radius">
								<image class="radius" :src="ite" mode=""></image>
							</view>
						</view>
					</view>
					<view class="yellowBtn margin_top" @click.stop="qiangdanpt(item.id)">立即搶單</view>
				</template>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: 0,
				tabList: [{
					title: "商品訂單"
				}, {
					title: "跑腿訂單"
				}],
				list: {
					data: []
				}
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			qiangdan(id) {
				this.http.modal('搶單', '是否確認搶單', true, (res) => {
					if (res) {
						this.http.request('/api/goods/ordergoodsadd', 'POST', {
							id: id,
							takeaway_id: uni.getStorageSync("takeaway_id"),
						}).then(res => {
							this.http.toast(res.msg)
							if (res.code == 1) {
								this.getList()
							}
						})
					}
				})
			},
			qiangdanpt(id) { //跑腿
				this.http.modal('搶單', '是否確認搶單', true, (res) => {
					if (res) {
						this.http.request('/api/goods/orderrunadd', 'POST', {
							id: id,
							takeaway_id: uni.getStorageSync("takeaway_id"),
						}).then(res => {
							this.http.toast(res.msg)
							if (res.code == 1) {
								this.getList()
							}
						})
					}
				})
			},
			async getList() {
				let url = "/api/Goods/ordergoodslist"
				if (this.active == 1) {
					url = "/api/Goods/orderrunlist"
				}
				let res = await this.http.request(url, 'POST', {})
				if (res.code == 1) {
					if (this.active == 1) {
						res.data.forEach(item => {
							let images_arr = []
							if (item.images) {
								let arr2 = item.images.split(",")
								arr2.forEach(ite => {
									let text = this.imgUrlUser + ite
									images_arr.push(text)
								})
							}
							this.$set(item, "images_arr", images_arr)
						})
						console.log(res.data);
					}
					this.list.data = res.data

				} else if (res.code == 0) {
					this.http.toast(res.msg);
					this.list.data = []
				} else {
					this.http.toast('網絡開小差啦');
				}
			},
			change(e) {
				this.active = e.index
				this.getList()
			},
			jumpurl(url) {
				return false
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-tabs__wrapper__nav__item {
		flex: 1;
		white-space: nowrap;
	}

	/deep/.u-tabs {
		padding: 0 20rpx;
	}

	.listleftimg1 {
		width: 120rpx;
		height: 120rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.imgBox {
		width: 40rpx;
		min-width: 40rpx;
		height: 40rpx;
	}

	.fromImg {
		width: 9rpx;
		height: 30rpx;
		margin-left: 15rpx;
	}

	.notes {
		background: #F5F6FA;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
	}

	.specBox {
		padding: 10rpx;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		border: 1rpx solid #FF8505;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
	}
</style>